#include "tunnelfilter.h"
#include <iostream>
#include <stdio.h>
#include <string.h>

AI_SOKOBAN::Tunnelfilter::Tunnelfilter(){

}

double AI_SOKOBAN::Tunnelfilter::evalLevel(const Level& level, const Move& move)
{
	Direction dir = move.getDir();
	int d_x = 0;
	int d_y = 0;

	if(dir == UP)
      d_x = 1;
    else if(dir == DOWN)
      d_x = 1;
    else if(dir == RIGHT)
      d_y = 1;
    else if(dir == LEFT)
      d_y = 1;
    else
      std::cout << "error: no direction!" << std::endl;


	if((level.at(move.getBoxNextX(), move.getBoxNextY()) == ' ')){
		if((level.at(move.getBoxCurrentX() + d_x, move.getBoxCurrentY() + d_y) == '#') && (level.at(move.getBoxCurrentX() - d_x, move.getBoxCurrentY() - d_y) == '#')){
			if((level.at(move.getBoxNextX() + d_x, move.getBoxNextY() + d_y) == '#') && (level.at(move.getBoxNextX() - d_x, move.getBoxNextY() - d_y) == '#')) return 10;
			//else if((level.at(move.getBoxNextX() + d_x, move.getBoxNextY() + d_y) == ' ') && (level.at(move.getBoxNextX() - d_x, move.getBoxNextY() - d_y) == '#')) return 10;
			//else if((level.at(move.getBoxNextX() + d_x, move.getBoxNextY() + d_y) == '#') && (level.at(move.getBoxNextX() - d_x, move.getBoxNextY() - d_y) == ' ')) return 10;
			//else if((level.at(move.getBoxNextX() + d_x, move.getBoxNextY() + d_y) == '-') && (level.at(move.getBoxNextX() - d_x, move.getBoxNextY() - d_y) == '#')) return 10;
			//else if((level.at(move.getBoxNextX() + d_x, move.getBoxNextY() + d_y) == '#') && (level.at(move.getBoxNextX() - d_x, move.getBoxNextY() - d_y) == '-')) return 10;
			//else if((level.at(move.getBoxNextX() + d_x, move.getBoxNextY() + d_y) == 'X') && (level.at(move.getBoxNextX() - d_x, move.getBoxNextY() - d_y) == '#')) return 10;
			//else if((level.at(move.getBoxNextX() + d_x, move.getBoxNextY() + d_y) == '#') && (level.at(move.getBoxNextX() - d_x, move.getBoxNextY() - d_y) == 'X')) return 10;
		}
	}
	return 1;
}
